﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameLogic {
	public class Interactive {
		public static void Play(Board startBoard) {
			while (true) {
				var board = startBoard;
				char c;
				do {
					Console.Clear();
					board.Print();
					var k = Console.ReadKey();
					c = k.KeyChar;
					switch (k.Key) {
						case ConsoleKey.LeftArrow: c = 'L'; break;
						case ConsoleKey.RightArrow: c = 'R'; break;
						case ConsoleKey.DownArrow: c = 'D'; break;
						case ConsoleKey.UpArrow: c = 'U'; break;
						case ConsoleKey.Spacebar: c = 'W'; break;
						case ConsoleKey.A: c = 'A'; break;
						case ConsoleKey.R: board = startBoard; continue; 
						case ConsoleKey.Backspace: if (board.Prev != null) { board = board.Prev;  }; continue;
						case ConsoleKey.Escape: Environment.Exit(0); break;
						default: continue;
					}

					board = new Board(board, c);
					Console.WriteLine(c);
				} while (c != 'q' && board.State == GameState.Running);
				Console.Clear();
				board.Print();
				Console.ReadLine();
				board = startBoard;
			}
		}
	}
}

